<template>
  <div class="date-management">
    <div class="container mx-auto px-4 py-6">
      <!-- 页面头部 -->
      <div class="page-header mb-6">
        <div class="flex justify-between items-center">
          <div>
            <h1 class="page-title">鉴定日期管理</h1>
            <p class="text-gray-600">管理和分配鉴定日期，合理安排鉴定工作</p>
          </div>
          <div class="flex gap-3">
            <el-button type="info" @click="showBatchAssignDialog">
              <i class="fas fa-tasks mr-2"></i>批量分配
            </el-button>
            <el-button type="success" @click="exportSchedule">
              <i class="fas fa-download mr-2"></i>导出日程
            </el-button>
            <el-button type="primary" @click="addNewDate">
              <i class="fas fa-plus mr-2"></i>新增日期
            </el-button>
          </div>
        </div>
      </div>

      <!-- 统计卡片 -->
      <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6">
        <div class="stat-card">
          <div class="stat-icon bg-blue-100">
            <i class="fas fa-calendar-alt text-blue-600"></i>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.totalDates }}</div>
            <div class="stat-label">总鉴定日期</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon bg-green-100">
            <i class="fas fa-check-circle text-green-600"></i>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.scheduledCases }}</div>
            <div class="stat-label">已安排案件</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon bg-orange-100">
            <i class="fas fa-clock text-orange-600"></i>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.availableSlots }}</div>
            <div class="stat-label">可用时段</div>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon bg-purple-100">
            <i class="fas fa-users text-purple-600"></i>
          </div>
          <div class="stat-content">
            <div class="stat-number">{{ stats.totalCapacity }}</div>
            <div class="stat-label">总接诊容量</div>
          </div>
        </div>
      </div>

      <!-- 主要内容区域 -->
      <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <!-- 日历视图 -->
        <div class="lg:col-span-2">
          <div class="calendar-section">
            <div class="section-header">
              <h2 class="section-title">鉴定日程安排</h2>
              <div class="view-controls">
                <el-radio-group v-model="calendarView" size="small">
                  <el-radio-button label="month">月视图</el-radio-button>
                  <el-radio-button label="week">周视图</el-radio-button>
                  <el-radio-button label="day">日视图</el-radio-button>
                </el-radio-group>
              </div>
            </div>
            
            <!-- 日历组件 -->
            <div class="calendar-container">
              <el-calendar v-model="selectedDate" @input="handleDateChange">
                <template #dateCell="{ data }">
                  <div 
                    class="calendar-cell"
                    :class="getCellClass(data.date)"
                    @click="selectDate(data.date)"
                  >
                    <div class="cell-date">{{ data.date.getDate() }}</div>
                    <div class="cell-info" v-if="getDateInfo(data.date)">
                      <div class="case-count">
                        <i class="fas fa-file-medical"></i>
                        {{ getDateInfo(data.date).caseCount }}件
                      </div>
                      <div class="capacity-info">
                        <span 
                          class="capacity-bar"
                          :style="{ width: getCapacityPercentage(data.date) + '%' }"
                          :class="getCapacityClass(data.date)"
                        ></span>
                      </div>
                    </div>
                  </div>
                </template>
              </el-calendar>
            </div>
          </div>
        </div>

        <!-- 右侧面板 -->
        <div class="sidebar-panel">
          <!-- 日期详情 -->
          <div class="info-card mb-6">
            <div class="card-header">
              <h3 class="card-title">
                <i class="fas fa-calendar-day text-blue-600"></i>
                {{ formatSelectedDate() }}
              </h3>
            </div>
            <div class="card-content">
              <div v-if="selectedDateInfo" class="date-details">
                <div class="detail-item">
                  <span class="detail-label">预约案件：</span>
                  <span class="detail-value">{{ selectedDateInfo.caseCount }}件</span>
                </div>
                <div class="detail-item">
                  <span class="detail-label">可用容量：</span>
                  <span class="detail-value">{{ selectedDateInfo.remainingCapacity }}人</span>
                </div>
                <div class="detail-item">
                  <span class="detail-label">负责鉴定师：</span>
                  <span class="detail-value">{{ selectedDateInfo.assignedExperts.join(', ') }}</span>
                </div>
                <div class="detail-item">
                  <span class="detail-label">状态：</span>
                  <el-tag :type="getStatusType(selectedDateInfo.status)">
                    {{ getStatusText(selectedDateInfo.status) }}
                  </el-tag>
                </div>
              </div>
              <div v-else class="no-data">
                <i class="fas fa-calendar-times text-gray-400 text-2xl mb-2"></i>
                <p class="text-gray-500">该日期暂无安排</p>
              </div>
            </div>
          </div>

          <!-- 快速操作 -->
          <div class="info-card mb-6">
            <div class="card-header">
              <h3 class="card-title">
                <i class="fas fa-bolt text-yellow-600"></i>
                快速操作
              </h3>
            </div>
            <div class="card-content">
              <div class="action-buttons">
                <el-button 
                  type="primary" 
                  size="small" 
                  @click="addCaseToDate" 
                  :disabled="!selectedDateInfo || selectedDateInfo.remainingCapacity <= 0"
                  block
                >
                  <i class="fas fa-plus mr-2"></i>
                  添加案件
                </el-button>
                <el-button 
                  size="small" 
                  @click="viewDateDetails" 
                  :disabled="!selectedDateInfo"
                  block
                >
                  <i class="fas fa-eye mr-2"></i>
                  查看详情
                </el-button>
                <el-button 
                  size="small" 
                  @click="editDateSettings" 
                  :disabled="!selectedDateInfo"
                  block
                >
                  <i class="fas fa-cog mr-2"></i>
                  设置配置
                </el-button>
                <el-button 
                  type="warning" 
                  size="small" 
                  @click="clearDateSchedule" 
                  :disabled="!selectedDateInfo || selectedDateInfo.caseCount === 0"
                  block
                >
                  <i class="fas fa-trash mr-2"></i>
                  清空安排
                </el-button>
              </div>
            </div>
          </div>

          <!-- 案件列表 -->
          <div class="info-card">
            <div class="card-header">
              <h3 class="card-title">
                <i class="fas fa-list text-green-600"></i>
                今日案件列表
              </h3>
            </div>
            <div class="card-content">
              <div v-if="selectedDateCases.length > 0" class="case-list">
                <div 
                  v-for="case_ in selectedDateCases" 
                  :key="case_.id"
                  class="case-item"
                >
                  <div class="case-info">
                    <div class="case-number">{{ case_.caseNumber }}</div>
                    <div class="case-client">{{ case_.clientName }}</div>
                    <div class="case-time">
                      <i class="fas fa-clock mr-1"></i>
                      {{ case_.appointmentTime }}
                    </div>
                  </div>
                  <div class="case-actions">
                    <el-button size="mini" type="text" @click="editCase(case_)">
                      <i class="fas fa-edit"></i>
                    </el-button>
                    <el-button size="mini" type="text" @click="removeCase(case_)">
                      <i class="fas fa-times text-red-500"></i>
                    </el-button>
                  </div>
                </div>
              </div>
              <div v-else class="no-cases">
                <i class="fas fa-clipboard-list text-gray-400 text-xl mb-2"></i>
                <p class="text-gray-500 text-sm">暂无案件安排</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 添加案件到日期的对话框 -->
    <el-dialog 
      v-model="showCaseDialog" 
      title="添加案件到指定日期" 
      width="600px"
      @close="resetCaseDialog"
    >
      <div class="case-assignment">
        <div class="form-section">
          <label class="form-label">选择案件</label>
          <el-select v-model="selectedCaseId" placeholder="请选择要安排的案件" filterable clearable>
            <el-option 
              v-for="case_ in availableCases" 
              :key="case_.id"
              :label="`${case_.caseNumber} - ${case_.clientName}`"
              :value="case_.id"
            >
              <div class="option-content">
                <div class="option-title">{{ case_.caseNumber }}</div>
                <div class="option-subtitle">{{ case_.clientName }} | {{ case_.caseType }}</div>
              </div>
            </el-option>
          </el-select>
        </div>

        <div class="form-section">
          <label class="form-label">预约时间</label>
          <el-time-picker 
            v-model="appointmentTime" 
            placeholder="选择具体时间"
            format="HH:mm"
            value-format="HH:mm"
          />
        </div>

        <div class="form-section">
          <label class="form-label">分配鉴定师</label>
          <el-select v-model="assignedExpert" placeholder="选择鉴定师">
            <el-option 
              v-for="expert in availableExperts" 
              :key="expert.id"
              :label="expert.name"
              :value="expert.id"
            />
          </el-select>
        </div>

        <div class="form-section">
          <label class="form-label">备注说明</label>
          <el-input 
            v-model="appointmentNotes" 
            type="textarea" 
            :rows="3" 
            placeholder="输入备注说明..."
          />
        </div>
      </div>

      <template #footer>
        <div class="dialog-actions">
          <el-button @click="showCaseDialog = false">取消</el-button>
          <el-button type="primary" @click="confirmCaseAssignment">确定安排</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 日期设置对话框 -->
    <el-dialog 
      v-model="showSettingsDialog" 
      title="日期设置" 
      width="500px"
      @close="resetSettingsDialog"
    >
      <div class="date-settings">
        <div class="form-section">
          <label class="form-label">最大接诊容量</label>
          <el-input-number 
            v-model="dateSettings.maxCapacity" 
            :min="1" 
            :max="20"
            placeholder="设置该日期最大接诊人数"
          />
        </div>

        <div class="form-section">
          <label class="form-label">工作时间</label>
          <el-time-picker 
            v-model="dateSettings.workingHours" 
            is-range
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            format="HH:mm"
            value-format="HH:mm"
          />
        </div>

        <div class="form-section">
          <label class="form-label">可用状态</label>
          <el-radio-group v-model="dateSettings.status">
            <el-radio label="available">可用</el-radio>
            <el-radio label="limited">受限</el-radio>
            <el-radio label="unavailable">不可用</el-radio>
          </el-radio-group>
        </div>

        <div class="form-section">
          <label class="form-label">备注</label>
          <el-input 
            v-model="dateSettings.notes" 
            type="textarea" 
            :rows="2" 
            placeholder="输入日期相关备注..."
          />
        </div>
      </div>

      <template #footer>
        <div class="dialog-actions">
          <el-button @click="showSettingsDialog = false">取消</el-button>
          <el-button type="primary" @click="saveDateSettings">保存设置</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 批量分配对话框 -->
    <el-dialog 
      v-model="showBatchDialog" 
      title="批量分配鉴定案件" 
      width="800px"
      @close="resetBatchDialog"
    >
      <div class="batch-assignment">
        <!-- 筛选区域 -->
        <div class="filter-section mb-4">
          <div class="flex items-center gap-4">
            <div class="filter-item">
              <label class="form-label">流程类型：</label>
              <el-select v-model="batchFilters.processType" placeholder="全部" size="small" clearable>
                <el-option label="诉前" value="pre-litigation"></el-option>
                <el-option label="诉中" value="litigation"></el-option>
                <el-option label="和谈" value="mediation"></el-option>
              </el-select>
            </div>
            <div class="filter-item">
              <label class="form-label">优先级：</label>
              <el-select v-model="batchFilters.priority" placeholder="全部" size="small" clearable>
                <el-option label="紧急" value="urgent"></el-option>
                <el-option label="高" value="high"></el-option>
                <el-option label="中" value="medium"></el-option>
                <el-option label="低" value="low"></el-option>
              </el-select>
            </div>
            <el-button type="primary" size="small" @click="refreshPendingCases">
              <i class="fas fa-sync mr-1"></i>刷新
            </el-button>
          </div>
        </div>

        <!-- 待分配案件列表 -->
        <div class="pending-cases-section">
          <div class="section-header">
            <h4 class="section-subtitle">
              <i class="fas fa-clipboard-list text-orange-600"></i>
              待分配案件列表 ({{ filteredPendingCases.length }}件)
            </h4>
            <div class="batch-controls">
              <el-checkbox 
                v-model="selectAllPending" 
                @change="handleSelectAllPending"
                :indeterminate="isIndeterminate"
              >
                全选
              </el-checkbox>
            </div>
          </div>
          
          <div class="cases-grid">
            <div 
              v-for="case_ in filteredPendingCases" 
              :key="case_.id"
              class="case-card"
              :class="{ 'selected': selectedPendingCases.includes(case_.id) }"
              @click="toggleCaseSelection(case_.id)"
            >
              <el-checkbox 
                v-model="selectedPendingCases"
                :value="case_.id"
                @click.stop
                class="case-checkbox"
              />
              <div class="case-header">
                <span class="case-number">{{ case_.caseNumber }}</span>
                <el-tag 
                  :type="getPriorityType(case_.priority)" 
                  size="mini"
                >
                  {{ getPriorityText(case_.priority) }}
                </el-tag>
              </div>
              <div class="case-info">
                <div class="info-row">
                  <span class="info-label">当事人：</span>
                  <span class="info-value">{{ case_.clientName }}</span>
                </div>
                <div class="info-row">
                  <span class="info-label">类型：</span>
                  <span class="info-value">{{ case_.caseType }}</span>
                </div>
                <div class="info-row">
                  <span class="info-label">流程：</span>
                  <el-tag size="mini" :type="getProcessTypeColor(case_.processType)">
                    {{ getProcessTypeText(case_.processType) }}
                  </el-tag>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 分配设置 -->
        <div class="assignment-settings" v-if="selectedPendingCases.length > 0">
          <h4 class="section-subtitle">
            <i class="fas fa-cogs text-blue-600"></i>
            分配设置 (已选择{{ selectedPendingCases.length }}件案件)
          </h4>
          
          <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div class="form-section">
              <label class="form-label">分配策略</label>
              <el-radio-group v-model="batchSettings.strategy">
                <el-radio label="auto">自动分配</el-radio>
                <el-radio label="manual">手动指定</el-radio>
              </el-radio-group>
            </div>
            
            <div class="form-section" v-if="batchSettings.strategy === 'manual'">
              <label class="form-label">指定日期</label>
              <el-date-picker 
                v-model="batchSettings.targetDate" 
                type="date"
                placeholder="选择日期"
                :disabled-date="disabledDate"
                size="small"
              />
            </div>
            
            <div class="form-section" v-if="batchSettings.strategy === 'manual'">
              <label class="form-label">指定鉴定师</label>
              <el-select v-model="batchSettings.targetExpert" placeholder="选择鉴定师" size="small">
                <el-option 
                  v-for="expert in availableExperts" 
                  :key="expert.id"
                  :label="expert.name"
                  :value="expert.id"
                />
              </el-select>
            </div>
          </div>

          <div class="auto-assignment-preview" v-if="batchSettings.strategy === 'auto'">
            <h5 class="preview-title">自动分配预览</h5>
            <div class="preview-content">
              <div 
                v-for="assignment in autoAssignmentPreview" 
                :key="assignment.date"
                class="assignment-preview-item"
              >
                <div class="assignment-date">
                  <i class="fas fa-calendar mr-2"></i>
                  {{ formatDate(assignment.date) }}
                </div>
                <div class="assignment-details">
                  <span class="assignment-count">{{ assignment.cases.length }}件案件</span>
                  <span class="assignment-capacity">
                    剩余容量: {{ assignment.remainingCapacity }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <template #footer>
        <div class="dialog-actions">
          <el-button @click="showBatchDialog = false">取消</el-button>
          <el-button 
            type="primary" 
            @click="confirmBatchAssignment"
            :disabled="selectedPendingCases.length === 0"
          >
            确认分配 ({{ selectedPendingCases.length }}件)
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { ref, reactive, computed, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'

export default {
  name: 'DateManagement',
  setup() {
    const selectedDate = ref(new Date())
    const calendarView = ref('month')
    const showCaseDialog = ref(false)
    const showSettingsDialog = ref(false)
    const showBatchDialog = ref(false)
    
    // 统计数据
    const stats = reactive({
      totalDates: 45,      // 已配置的鉴定日期总数
      scheduledCases: 128, // 已安排的案件数量
      availableSlots: 67,  // 剩余可用时段
      totalCapacity: 195   // 总接诊容量
    })
    
    // 日期数据
    const dateSchedules = ref([
      {
        date: '2024-01-20',
        caseCount: 5,
        maxCapacity: 8,
        remainingCapacity: 3,
        assignedExperts: ['李法医', '王专家'],
        status: 'available',
        cases: [
          { id: 1, caseNumber: 'TA2024001', clientName: '张某', appointmentTime: '09:00', expert: '李法医' },
          { id: 2, caseNumber: 'TA2024002', clientName: '李某', appointmentTime: '10:30', expert: '王专家' },
          { id: 3, caseNumber: 'TA2024003', clientName: '王某', appointmentTime: '14:00', expert: '李法医' },
          { id: 4, caseNumber: 'TA2024004', clientName: '陈某', appointmentTime: '15:30', expert: '王专家' },
          { id: 5, caseNumber: 'TA2024005', clientName: '刘某', appointmentTime: '16:00', expert: '李法医' }
        ]
      },
      {
        date: '2024-01-22',
        caseCount: 3,
        maxCapacity: 6,
        remainingCapacity: 3,
        assignedExperts: ['赵专家'],
        status: 'available',
        cases: [
          { id: 6, caseNumber: 'TA2024006', clientName: '孙某', appointmentTime: '09:30', expert: '赵专家' },
          { id: 7, caseNumber: 'TA2024007', clientName: '周某', appointmentTime: '11:00', expert: '赵专家' },
          { id: 8, caseNumber: 'TA2024008', clientName: '吴某', appointmentTime: '14:30', expert: '赵专家' }
        ]
      },
      {
        date: '2024-01-25',
        caseCount: 8,
        maxCapacity: 8,
        remainingCapacity: 0,
        assignedExperts: ['李法医', '王专家', '孙法医'],
        status: 'full',
        cases: []
      },
      {
        date: '2024-01-30',
        caseCount: 0,
        maxCapacity: 10,
        remainingCapacity: 10,
        assignedExperts: ['李法医', '王专家'],
        status: 'available',
        cases: []
      }
    ])
    
    // 可用案件列表
    const availableCases = ref([
      { id: 101, caseNumber: 'TA2024015', clientName: '张某某', caseType: '交通事故', priority: 'high' },
      { id: 102, caseNumber: 'TA2024016', clientName: '李某某', caseType: '交通事故', priority: 'medium' },
      { id: 103, caseNumber: 'TA2024017', clientName: '王某某', caseType: '交通事故', priority: 'urgent' },
      { id: 104, caseNumber: 'TA2024018', clientName: '陈某某', caseType: '交通事故', priority: 'low' },
      { id: 105, caseNumber: 'TA2024019', clientName: '刘某某', caseType: '交通事故', priority: 'high' }
    ])
    
    // 待分配案件列表（从待鉴定案件页面获取）
    const pendingCases = ref([
      { id: 201, caseNumber: 'TA2024020', clientName: '王大明', caseType: '交通事故', priority: 'urgent', processType: 'pre-litigation' },
      { id: 202, caseNumber: 'TA2024021', clientName: '李小华', caseType: '交通事故', priority: 'high', processType: 'litigation' },
      { id: 203, caseNumber: 'TA2024022', clientName: '张三丰', caseType: '交通事故', priority: 'medium', processType: 'mediation' },
      { id: 204, caseNumber: 'TA2024023', clientName: '赵四海', caseType: '交通事故', priority: 'high', processType: 'pre-litigation' },
      { id: 205, caseNumber: 'TA2024024', clientName: '孙悟空', caseType: '交通事故', priority: 'low', processType: 'litigation' },
      { id: 206, caseNumber: 'TA2024025', clientName: '周星驰', caseType: '交通事故', priority: 'urgent', processType: 'mediation' },
      { id: 207, caseNumber: 'TA2024026', clientName: '刘德华', caseType: '交通事故', priority: 'medium', processType: 'pre-litigation' },
      { id: 208, caseNumber: 'TA2024027', clientName: '成龙', caseType: '交通事故', priority: 'high', processType: 'litigation' }
    ])
    
    // 批量分配相关状态
    const selectedPendingCases = ref([])
    const selectAllPending = ref(false)
    const batchFilters = reactive({
      processType: '',
      priority: ''
    })
    const batchSettings = reactive({
      strategy: 'auto',
      targetDate: null,
      targetExpert: ''
    })
    
    // 可用鉴定师列表
    const availableExperts = ref([
      { id: 1, name: '李法医', specialty: '人身损害' },
      { id: 2, name: '王专家', specialty: '车辆损失' },
      { id: 3, name: '赵专家', specialty: '因果关系' },
      { id: 4, name: '孙法医', specialty: '人身损害' },
      { id: 5, name: '郑专家', specialty: '综合鉴定' }
    ])
    
    // 案件分配表单数据
    const selectedCaseId = ref('')
    const appointmentTime = ref('')
    const assignedExpert = ref('')
    const appointmentNotes = ref('')
    
    // 日期设置表单数据
    const dateSettings = reactive({
      maxCapacity: 8,
      workingHours: ['09:00', '17:00'],
      status: 'available',
      notes: ''
    })
    
    // 计算属性
    const selectedDateInfo = computed(() => {
      const dateStr = dayjs(selectedDate.value).format('YYYY-MM-DD')
      return dateSchedules.value.find(item => item.date === dateStr)
    })
    
    const selectedDateCases = computed(() => {
      return selectedDateInfo.value ? selectedDateInfo.value.cases : []
    })
    
    // 筛选后的待分配案件
    const filteredPendingCases = computed(() => {
      let filtered = pendingCases.value
      
      if (batchFilters.processType) {
        filtered = filtered.filter(case_ => case_.processType === batchFilters.processType)
      }
      
      if (batchFilters.priority) {
        filtered = filtered.filter(case_ => case_.priority === batchFilters.priority)
      }
      
      return filtered
    })
    
    // 全选状态
    const isIndeterminate = computed(() => {
      const selectedCount = selectedPendingCases.value.length
      const totalCount = filteredPendingCases.value.length
      return selectedCount > 0 && selectedCount < totalCount
    })
    
    // 自动分配预览
    const autoAssignmentPreview = computed(() => {
      if (batchSettings.strategy !== 'auto' || selectedPendingCases.value.length === 0) {
        return []
      }
      
      // 简单的自动分配算法：按日期容量分配
      const assignments = []
      const availableDates = dateSchedules.value.filter(d => d.remainingCapacity > 0)
      let currentDateIndex = 0
      
      for (let i = 0; i < selectedPendingCases.value.length; i++) {
        if (currentDateIndex >= availableDates.length) break
        
        const currentDate = availableDates[currentDateIndex]
        let assignment = assignments.find(a => a.date === currentDate.date)
        
        if (!assignment) {
          assignment = {
            date: currentDate.date,
            cases: [],
            remainingCapacity: currentDate.remainingCapacity
          }
          assignments.push(assignment)
        }
        
        if (assignment.remainingCapacity > 0) {
          assignment.cases.push(selectedPendingCases.value[i])
          assignment.remainingCapacity--
        } else {
          currentDateIndex++
          i-- // 重新处理当前案件
        }
      }
      
      return assignments
    })
    
    // 获取日期信息
    const getDateInfo = (date) => {
      const dateStr = dayjs(date).format('YYYY-MM-DD')
      return dateSchedules.value.find(item => item.date === dateStr)
    }
    
    // 获取容量百分比
    const getCapacityPercentage = (date) => {
      const info = getDateInfo(date)
      if (!info) return 0
      return ((info.maxCapacity - info.remainingCapacity) / info.maxCapacity) * 100
    }
    
    // 获取容量样式类
    const getCapacityClass = (date) => {
      const percentage = getCapacityPercentage(date)
      if (percentage >= 90) return 'capacity-full'
      if (percentage >= 70) return 'capacity-high'
      if (percentage >= 40) return 'capacity-medium'
      return 'capacity-low'
    }
    
    // 获取日期单元格样式类
    const getCellClass = (date) => {
      const info = getDateInfo(date)
      if (!info) return ''
      
      const classes = []
      if (info.status === 'full' || info.remainingCapacity === 0) {
        classes.push('date-full')
      } else if (info.status === 'limited') {
        classes.push('date-limited')
      } else if (info.status === 'available') {
        classes.push('date-available')
      }
      
      if (dayjs(date).isSame(selectedDate.value, 'day')) {
        classes.push('date-selected')
      }
      
      return classes.join(' ')
    }
    
    // 格式化选中日期
    const formatSelectedDate = () => {
      return dayjs(selectedDate.value).format('YYYY年MM月DD日 dddd')
    }
    
    // 获取状态类型
    const getStatusType = (status) => {
      const types = {
        'available': 'success',
        'limited': 'warning',
        'full': 'danger',
        'unavailable': 'info'
      }
      return types[status] || 'info'
    }
    
    // 获取状态文本
    const getStatusText = (status) => {
      const texts = {
        'available': '可用',
        'limited': '受限',
        'full': '已满',
        'unavailable': '不可用'
      }
      return texts[status] || '未知'
    }
    
    // 获取优先级类型
    const getPriorityType = (priority) => {
      const types = {
        'urgent': 'danger',
        'high': 'warning', 
        'medium': 'info',
        'low': 'success'
      }
      return types[priority] || 'info'
    }
    
    // 获取优先级文本
    const getPriorityText = (priority) => {
      const texts = {
        'urgent': '紧急',
        'high': '高',
        'medium': '中', 
        'low': '低'
      }
      return texts[priority] || '未知'
    }
    
    // 获取流程类型颜色
    const getProcessTypeColor = (processType) => {
      const colors = {
        'pre-litigation': 'success',
        'litigation': 'warning',
        'mediation': 'info'
      }
      return colors[processType] || 'info'
    }
    
    // 获取流程类型文本
    const getProcessTypeText = (processType) => {
      const texts = {
        'pre-litigation': '诉前',
        'litigation': '诉中',
        'mediation': '和谈'
      }
      return texts[processType] || '未知'
    }
    
    // 格式化日期
    const formatDate = (date) => {
      return dayjs(date).format('MM月DD日')
    }
    
    // 禁用过去日期
    const disabledDate = (time) => {
      return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
    }
    
    // 事件处理方法
    const handleDateChange = (date) => {
      selectedDate.value = date
    }
    
    const selectDate = (date) => {
      selectedDate.value = date
    }
    
    const addNewDate = () => {
      ElMessage.info('新增日期功能开发中...')
    }
    
    const exportSchedule = () => {
      ElMessage.info('导出日程功能开发中...')
    }
    
    const addCaseToDate = () => {
      if (!selectedDateInfo.value) {
        ElMessage.warning('请先选择一个日期')
        return
      }
      if (selectedDateInfo.value.remainingCapacity <= 0) {
        ElMessage.warning('该日期已无剩余容量')
        return
      }
      showCaseDialog.value = true
    }
    
    const viewDateDetails = () => {
      if (!selectedDateInfo.value) {
        ElMessage.warning('请先选择一个日期')
        return
      }
      ElMessage.info('查看详情功能开发中...')
    }
    
    const editDateSettings = () => {
      if (!selectedDateInfo.value) {
        ElMessage.warning('请先选择一个日期')
        return
      }
      
      // 填充当前设置
      dateSettings.maxCapacity = selectedDateInfo.value.maxCapacity
      dateSettings.status = selectedDateInfo.value.status
      dateSettings.notes = ''
      
      showSettingsDialog.value = true
    }
    
    const clearDateSchedule = async () => {
      if (!selectedDateInfo.value || selectedDateInfo.value.caseCount === 0) {
        return
      }
      
      try {
        await ElMessageBox.confirm(
          `确定要清空 ${formatSelectedDate()} 的所有案件安排吗？`,
          '确认清空',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        )
        
        // 清空案件安排
        selectedDateInfo.value.caseCount = 0
        selectedDateInfo.value.cases = []
        selectedDateInfo.value.remainingCapacity = selectedDateInfo.value.maxCapacity
        selectedDateInfo.value.status = 'available'
        
        ElMessage.success('日期安排已清空')
      } catch {
        // 用户取消操作
      }
    }
    
    const confirmCaseAssignment = () => {
      if (!selectedCaseId.value || !appointmentTime.value || !assignedExpert.value) {
        ElMessage.warning('请填写完整的预约信息')
        return
      }
      
      // 获取选中的案件和鉴定师信息
      const selectedCase = availableCases.value.find(c => c.id === selectedCaseId.value)
      const expert = availableExperts.value.find(e => e.id === assignedExpert.value)
      
      if (!selectedCase || !expert) {
        ElMessage.error('案件或鉴定师信息错误')
        return
      }
      
      // 创建新的案件安排
      const newCaseSchedule = {
        id: Date.now(),
        caseNumber: selectedCase.caseNumber,
        clientName: selectedCase.clientName,
        appointmentTime: appointmentTime.value,
        expert: expert.name,
        notes: appointmentNotes.value
      }
      
      // 更新日期信息
      if (selectedDateInfo.value) {
        selectedDateInfo.value.cases.push(newCaseSchedule)
        selectedDateInfo.value.caseCount++
        selectedDateInfo.value.remainingCapacity--
        
        if (selectedDateInfo.value.remainingCapacity === 0) {
          selectedDateInfo.value.status = 'full'
        }
        
        // 添加鉴定师到已分配列表
        if (!selectedDateInfo.value.assignedExperts.includes(expert.name)) {
          selectedDateInfo.value.assignedExperts.push(expert.name)
        }
      }
      
      ElMessage.success('案件已成功安排到指定日期')
      showCaseDialog.value = false
      resetCaseDialog()
    }
    
    const saveDateSettings = () => {
      if (!selectedDateInfo.value) {
        ElMessage.warning('请先选择一个日期')
        return
      }
      
      // 更新日期设置
      selectedDateInfo.value.maxCapacity = dateSettings.maxCapacity
      selectedDateInfo.value.status = dateSettings.status
      
      // 重新计算剩余容量
      selectedDateInfo.value.remainingCapacity = 
        dateSettings.maxCapacity - selectedDateInfo.value.caseCount
      
      // 如果容量不足，更新状态
      if (selectedDateInfo.value.remainingCapacity <= 0) {
        selectedDateInfo.value.status = 'full'
      }
      
      ElMessage.success('日期设置已保存')
      showSettingsDialog.value = false
      resetSettingsDialog()
    }
    
    const editCase = (case_) => {
      ElMessage.info(`编辑案件 ${case_.caseNumber} 功能开发中...`)
    }
    
    const removeCase = async (case_) => {
      try {
        await ElMessageBox.confirm(
          `确定要移除案件 ${case_.caseNumber} 吗？`,
          '确认移除',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        )
        
        // 从案件列表中移除
        const index = selectedDateInfo.value.cases.findIndex(c => c.id === case_.id)
        if (index > -1) {
          selectedDateInfo.value.cases.splice(index, 1)
          selectedDateInfo.value.caseCount--
          selectedDateInfo.value.remainingCapacity++
          
          if (selectedDateInfo.value.status === 'full') {
            selectedDateInfo.value.status = 'available'
          }
        }
        
        ElMessage.success('案件已移除')
      } catch {
        // 用户取消操作
      }
    }
    
    const resetCaseDialog = () => {
      selectedCaseId.value = ''
      appointmentTime.value = ''
      assignedExpert.value = ''
      appointmentNotes.value = ''
    }
    
    const resetSettingsDialog = () => {
      Object.assign(dateSettings, {
        maxCapacity: 8,
        workingHours: ['09:00', '17:00'],
        status: 'available',
        notes: ''
      })
    }
    
    // 批量分配相关方法
    const showBatchAssignDialog = () => {
      showBatchDialog.value = true
      refreshPendingCases()
    }
    
    const refreshPendingCases = () => {
      // 这里可以调用API刷新待分配案件列表
      ElMessage.success('案件列表已刷新')
    }
    
    const toggleCaseSelection = (caseId) => {
      const index = selectedPendingCases.value.indexOf(caseId)
      if (index > -1) {
        selectedPendingCases.value.splice(index, 1)
      } else {
        selectedPendingCases.value.push(caseId)
      }
      updateSelectAllState()
    }
    
    const handleSelectAllPending = () => {
      if (selectAllPending.value) {
        selectedPendingCases.value = filteredPendingCases.value.map(case_ => case_.id)
      } else {
        selectedPendingCases.value = []
      }
    }
    
    const updateSelectAllState = () => {
      const selectedCount = selectedPendingCases.value.length
      const totalCount = filteredPendingCases.value.length
      selectAllPending.value = selectedCount === totalCount && totalCount > 0
    }
    
    const confirmBatchAssignment = async () => {
      if (selectedPendingCases.value.length === 0) {
        ElMessage.warning('请选择要分配的案件')
        return
      }
      
      try {
        if (batchSettings.strategy === 'manual') {
          if (!batchSettings.targetDate || !batchSettings.targetExpert) {
            ElMessage.warning('手动分配模式下请指定日期和鉴定师')
            return
          }
          
          await performManualAssignment()
        } else {
          await performAutoAssignment()
        }
        
        ElMessage.success(`成功分配 ${selectedPendingCases.value.length} 件案件`)
        showBatchDialog.value = false
        resetBatchDialog()
      } catch (error) {
        ElMessage.error('批量分配失败: ' + error.message)
      }
    }
    
    const performManualAssignment = async () => {
      const targetDateStr = dayjs(batchSettings.targetDate).format('YYYY-MM-DD')
      let targetDateInfo = dateSchedules.value.find(d => d.date === targetDateStr)
      
      // 如果目标日期不存在，创建新的日期记录
      if (!targetDateInfo) {
        targetDateInfo = {
          date: targetDateStr,
          caseCount: 0,
          maxCapacity: 8,
          remainingCapacity: 8,
          assignedExperts: [],
          status: 'available',
          cases: []
        }
        dateSchedules.value.push(targetDateInfo)
      }
      
      // 检查容量
      if (targetDateInfo.remainingCapacity < selectedPendingCases.value.length) {
        throw new Error(`目标日期容量不足，剩余容量：${targetDateInfo.remainingCapacity}，需要：${selectedPendingCases.value.length}`)
      }
      
      // 获取鉴定师信息
      const expert = availableExperts.value.find(e => e.id === batchSettings.targetExpert)
      if (!expert) {
        throw new Error('指定的鉴定师不存在')
      }
      
      // 分配案件
      const selectedCases = pendingCases.value.filter(case_ => selectedPendingCases.value.includes(case_.id))
      
      selectedCases.forEach((case_, index) => {
        const newCase = {
          id: Date.now() + index,
          caseNumber: case_.caseNumber,
          clientName: case_.clientName,
          appointmentTime: `${9 + index}:00`, // 简单的时间分配
          expert: expert.name,
          notes: `批量分配 - ${getProcessTypeText(case_.processType)}`
        }
        
        targetDateInfo.cases.push(newCase)
      })
      
      // 更新统计信息
      targetDateInfo.caseCount += selectedPendingCases.value.length
      targetDateInfo.remainingCapacity -= selectedPendingCases.value.length
      
      if (!targetDateInfo.assignedExperts.includes(expert.name)) {
        targetDateInfo.assignedExperts.push(expert.name)
      }
      
      if (targetDateInfo.remainingCapacity === 0) {
        targetDateInfo.status = 'full'
      }
      
      // 从待分配列表中移除已分配的案件
      selectedPendingCases.value.forEach(caseId => {
        const index = pendingCases.value.findIndex(case_ => case_.id === caseId)
        if (index > -1) {
          pendingCases.value.splice(index, 1)
        }
      })
    }
    
    const performAutoAssignment = async () => {
      const assignments = autoAssignmentPreview.value
      if (assignments.length === 0) {
        throw new Error('无可用日期进行自动分配')
      }
      
      // 执行自动分配
      for (const assignment of assignments) {
        const targetDateInfo = dateSchedules.value.find(d => d.date === assignment.date)
        if (!targetDateInfo) continue
        
        const selectedCases = pendingCases.value.filter(case_ => 
          assignment.cases.some(assignedCase => assignedCase === case_.id)
        )
        
        selectedCases.forEach((case_, index) => {
          // 自动选择鉴定师
          const availableExpert = availableExperts.value[index % availableExperts.value.length]
          
          const newCase = {
            id: Date.now() + index,
            caseNumber: case_.caseNumber,
            clientName: case_.clientName,
            appointmentTime: `${9 + (targetDateInfo.caseCount + index)}:00`,
            expert: availableExpert.name,
            notes: `自动分配 - ${getProcessTypeText(case_.processType)}`
          }
          
          targetDateInfo.cases.push(newCase)
          
          if (!targetDateInfo.assignedExperts.includes(availableExpert.name)) {
            targetDateInfo.assignedExperts.push(availableExpert.name)
          }
        })
        
        // 更新统计信息
        targetDateInfo.caseCount += assignment.cases.length
        targetDateInfo.remainingCapacity -= assignment.cases.length
        
        if (targetDateInfo.remainingCapacity === 0) {
          targetDateInfo.status = 'full'
        }
      }
      
      // 从待分配列表中移除已分配的案件
      selectedPendingCases.value.forEach(caseId => {
        const index = pendingCases.value.findIndex(case_ => case_.id === caseId)
        if (index > -1) {
          pendingCases.value.splice(index, 1)
        }
      })
    }
    
    const resetBatchDialog = () => {
      selectedPendingCases.value = []
      selectAllPending.value = false
      Object.assign(batchFilters, {
        processType: '',
        priority: ''
      })
      Object.assign(batchSettings, {
        strategy: 'auto',
        targetDate: null,
        targetExpert: ''
      })
    }
    
    onMounted(() => {
      // 初始化选择今天
      selectedDate.value = new Date()
    })
    
    return {
      selectedDate,
      calendarView,
      showCaseDialog,
      showSettingsDialog,
      showBatchDialog,
      stats,
      dateSchedules,
      availableCases,
      availableExperts,
      pendingCases,
      selectedCaseId,
      appointmentTime,
      assignedExpert,
      appointmentNotes,
      dateSettings,
      selectedDateInfo,
      selectedDateCases,
      selectedPendingCases,
      selectAllPending,
      batchFilters,
      batchSettings,
      filteredPendingCases,
      isIndeterminate,
      autoAssignmentPreview,
      getDateInfo,
      getCapacityPercentage,
      getCapacityClass,
      getCellClass,
      formatSelectedDate,
      getStatusType,
      getStatusText,
      getPriorityType,
      getPriorityText,
      getProcessTypeColor,
      getProcessTypeText,
      formatDate,
      disabledDate,
      handleDateChange,
      selectDate,
      addNewDate,
      exportSchedule,
      addCaseToDate,
      viewDateDetails,
      editDateSettings,
      clearDateSchedule,
      confirmCaseAssignment,
      saveDateSettings,
      editCase,
      removeCase,
      resetCaseDialog,
      resetSettingsDialog,
      showBatchAssignDialog,
      refreshPendingCases,
      toggleCaseSelection,
      handleSelectAllPending,
      updateSelectAllState,
      confirmBatchAssignment,
      performManualAssignment,
      performAutoAssignment,
      resetBatchDialog
    }
  }
}
</script>

<style scoped>
.date-management {
  background: #f8fafc;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

.page-title {
  font-size: 28px;
  font-weight: bold;
  color: #1f2937;
  margin: 0;
}

/* 统计卡片 */
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.3s ease;
}

.stat-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-content {
  flex: 1;
}

.stat-number {
  font-size: 24px;
  font-weight: bold;
  color: #1f2937;
  line-height: 1;
}

.stat-label {
  font-size: 14px;
  color: #6b7280;
  margin-top: 4px;
}

/* 日历部分 */
.calendar-section {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
}

.calendar-container {
  margin-top: 20px;
}

/* 自定义日历单元格 */
.calendar-cell {
  position: relative;
  padding: 8px 4px;
  min-height: 80px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
  border: 2px solid transparent;
}

.calendar-cell:hover {
  background: #f0f9ff;
  border-color: #3b82f6;
}

.calendar-cell.date-selected {
  background: #3b82f6;
  color: white;
  border-color: #2563eb;
}

.calendar-cell.date-available {
  border-left: 3px solid #10b981;
}

.calendar-cell.date-limited {
  border-left: 3px solid #f59e0b;
}

.calendar-cell.date-full {
  border-left: 3px solid #ef4444;
  background: #fef2f2;
}

.cell-date {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.cell-info {
  font-size: 11px;
}

.case-count {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  color: #6b7280;
}

.calendar-cell.date-selected .case-count {
  color: rgba(255, 255, 255, 0.9);
}

.capacity-info {
  margin-top: 4px;
}

.capacity-bar {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: #10b981;
  transition: width 0.3s ease;
}

.capacity-bar.capacity-low {
  background: #10b981;
}

.capacity-bar.capacity-medium {
  background: #f59e0b;
}

.capacity-bar.capacity-high {
  background: #ef4444;
}

.capacity-bar.capacity-full {
  background: #991b1b;
}

/* 侧边栏面板 */
.sidebar-panel {
  display: flex;
  flex-direction: column;
}

.info-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.info-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.card-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
}

.card-content {
  padding-top: 4px;
}

/* 日期详情 */
.date-details {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}

.detail-item:last-child {
  border-bottom: none;
}

.detail-label {
  font-weight: 500;
  color: #6b7280;
  font-size: 14px;
}

.detail-value {
  color: #1f2937;
  font-size: 14px;
  font-weight: 500;
}

.no-data {
  text-align: center;
  padding: 20px 0;
}

/* 快速操作按钮 */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 案件列表 */
.case-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.case-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  transition: all 0.2s ease;
}

.case-item:hover {
  background: #f0f9ff;
  border-color: #3b82f6;
}

.case-info {
  flex: 1;
}

.case-number {
  font-weight: 600;
  color: #1f2937;
  font-size: 14px;
}

.case-client {
  color: #6b7280;
  font-size: 13px;
  margin-top: 2px;
}

.case-time {
  color: #6b7280;
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
}

.case-actions {
  display: flex;
  gap: 4px;
}

.no-cases {
  text-align: center;
  padding: 20px 0;
}

/* 对话框表单 */
.case-assignment,
.date-settings {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-label {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.option-content {
  display: flex;
  flex-direction: column;
}

.option-title {
  font-weight: 600;
  color: #1f2937;
}

.option-subtitle {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* 批量分配对话框样式 */
.batch-assignment {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.filter-section {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-item .form-label {
  min-width: 80px;
  font-size: 14px;
  color: #6b7280;
}

.pending-cases-section {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.section-subtitle {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.batch-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
}

.case-card {
  position: relative;
  padding: 16px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.2s ease;
}

.case-card:hover {
  border-color: #3b82f6;
  background: #f0f9ff;
}

.case-card.selected {
  border-color: #3b82f6;
  background: #eff6ff;
  box-shadow: 0 0 0 1px #3b82f6;
}

.case-checkbox {
  position: absolute;
  top: 12px;
  right: 12px;
}

.case-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-right: 24px;
}

.case-number {
  font-weight: 600;
  color: #1f2937;
  font-size: 14px;
}

.case-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.info-label {
  color: #6b7280;
  min-width: 50px;
}

.info-value {
  color: #1f2937;
  font-weight: 500;
}

.assignment-settings {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.auto-assignment-preview {
  margin-top: 16px;
  padding: 16px;
  background: white;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.preview-title {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin: 0 0 12px 0;
}

.preview-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.assignment-preview-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}

.assignment-date {
  display: flex;
  align-items: center;
  font-weight: 500;
  color: #1f2937;
  font-size: 14px;
}

.assignment-details {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.assignment-count {
  color: #3b82f6;
  font-weight: 500;
}

.assignment-capacity {
  color: #6b7280;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .date-management {
    padding: 16px;
  }
  
  .info-card,
  .calendar-section {
    padding: 16px;
  }
  
  .calendar-cell {
    min-height: 60px;
    padding: 4px 2px;
  }
  
  .cell-date {
    font-size: 12px;
  }
  
  .case-count {
    font-size: 10px;
  }
  
  .stat-card {
    padding: 16px;
  }
  
  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
  
  .stat-number {
    font-size: 20px;
  }
  
  .cases-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
  }
  
  .filter-section {
    padding: 12px;
  }
  
  .filter-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  
  .filter-item .form-label {
    min-width: auto;
  }
}
</style>

